import test from 'ava';
import fs from 'fs'
import path from 'path'
import { fileutil } from '../index.js'
let {
  mkdir,
  deldir,
  listFiles,
  getMd5
} = fileutil;

test('mkdir', t => {
  mkdir('mkdir/test');
  let rs = fs.existsSync('mkdir/test');
  t.is(rs, true);
});

test('deldir', t => {
  mkdir('mkdir/test');
  fs.writeFileSync('mkdir/test/1.txt', '1');
  let rs3 = deldir('mkdir');
  let rs = fs.existsSync('mkdir');
  t.is(rs3, !rs);
});

test('listFiles', t => {
  mkdir('mkdir/test');
  mkdir('mkdir/test2');
  fs.writeFileSync('mkdir/test/1.txt', '1');
  fs.writeFileSync('mkdir/test2/2.txt', '2');
  t.deepEqual(listFiles('mkdir'), ['test' + path.sep + '1.txt', 'test2' + path.sep + '2.txt']);
  deldir('mkdir');
  
});

test('getMd5', async t => {
  fs.writeFileSync('./md5.txt', '123321');
  let rst = await getMd5('./md5.txt')
  t.is(rst, 'c8837b23ff8aaa8a2dde915473ce0991');

  deldir('./md5.txt');
})
